﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Client.Commands
{
    class HelpCommand : ACommand
    {
        public override string CommandCode
        {
            get
            {
                return "help";
            }
        }

        public override string CommandHelpExplain
        {
            get
            {
                return "帮助";
            }
        }

        public override void SendCommand(string args)
        {
            var cmds = ACommand.Commands().OrderBy(s => s.CommandCode).ToList();
            int max = ACommand.Commands().Max(s => s.CommandCode.Length);
            foreach (var cmd in cmds)
            {
                Console.WriteLine(GetCode(cmd.CommandCode, max) + " " + cmd.CommandHelpExplain);
            }
        }

        private string GetCode(string code, int max)
        {
            if (code.Length >= max)
            {
                return code;
            }
            StringBuilder sb = new StringBuilder();
            sb.Append(code);
            for (int c = max - code.Length; c > 0; c--)
            {
                sb.Append(" ");
            }
            return sb.ToString();
        }
    }
}
